package com.ruoyi.decision.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.decision.domain.Scheme;
import com.ruoyi.decision.domain.Task;
import com.ruoyi.decision.mapper.SchemeMapper;
import com.ruoyi.decision.mapper.TaskMapper;
import com.ruoyi.decision.service.ISchemeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Locale;
import java.util.UUID;

/**
 * 决策方案Service业务层处理
 * 
 * @author zbw
 * @date 2022-07-20
 */
@Service
public class SchemeServiceImpl implements ISchemeService 
{
    @Autowired
    private SchemeMapper schemeMapper;
    @Autowired
    private TaskMapper taskMapper;

    /**
     * 查询决策方案
     * 
     * @param schemeId 决策方案主键
     * @return 决策方案
     */
    @Override
    public Scheme selectSchemeBySchemeId(String schemeId)
    {
        return schemeMapper.selectSchemeBySchemeId(schemeId);
    }

    /**
     * 查询决策方案列表
     * 
     * @param scheme 决策方案
     * @return 决策方案
     */
    @Override
    public List<Scheme> selectSchemeList(Scheme scheme)
    {
        return schemeMapper.selectSchemeList(scheme);
    }

    /**
     * 新增决策方案
     * 
     * @param scheme 决策方案
     * @return 结果
     */
    @Override
    public int insertScheme(Scheme scheme)
    {
        String schemeId = UUID.randomUUID().toString().toLowerCase(Locale.ROOT).replace("-","");
        scheme.setSchemeId(schemeId);
        scheme.setCreateTime(DateUtils.getNowDate());
        scheme.setSchemeReport(0);
        scheme.setSchemeExamine(0);
        schemeMapper.insertScheme(scheme);

        Task task = new Task();
        task.setTaskId(scheme.getTaskId());
        task.setTaskState(2);
        taskMapper.updateTask(task);

        return 1;
    }

    /**
     * 修改决策方案
     * 
     * @param scheme 决策方案
     * @return 结果
     */
    @Override
    public int updateScheme(Scheme scheme)
    {
        return schemeMapper.updateScheme(scheme);
    }

    /**
     * 批量删除决策方案
     * 
     * @param schemeIds 需要删除的决策方案主键
     * @return 结果
     */
    @Override
    public int deleteSchemeBySchemeIds(String[] schemeIds)
    {
        return schemeMapper.deleteSchemeBySchemeIds(schemeIds);
    }

    /**
     * 删除决策方案信息
     * 
     * @param schemeId 决策方案主键
     * @return 结果
     */
    @Override
    public int deleteSchemeBySchemeId(String schemeId)
    {
        return schemeMapper.deleteSchemeBySchemeId(schemeId);
    }

    @Override
    public int updateSchemeByExamine(String schemeId) {
        Scheme scheme = new Scheme();
        scheme.setSchemeReport(2);
        scheme.setSchemeExamine(1);
        scheme.setSchemeId(schemeId);
        return schemeMapper.updateScheme(scheme);
    }

    @Override
    public String insertSchemestrategy(Scheme scheme) {
        String schemeId = UUID.randomUUID().toString().toLowerCase(Locale.ROOT).replace("-","");
        scheme.setSchemeId(schemeId);
        scheme.setCreateTime(DateUtils.getNowDate());
        scheme.setSchemeReport(0);
        scheme.setSchemeExamine(0);
        int i = schemeMapper.insertScheme(scheme);

        return schemeId;
    }

    @Override
    public int updateSchemeByReport(String schemeId) {
        Scheme scheme = new Scheme();
        scheme.setSchemeReport(1);
        scheme.setSchemeId(schemeId);
        return schemeMapper.updateScheme(scheme);
    }
}
